<template>
	<view>
		<button @click="showToast">显示Toast</button>
		<button @click="showLoading">显示Loading</button>
		<button @click="getLocation">获取坐标</button>
		<button @click="chooseImage">相册选择照片</button>
		<button @click="setStorageSync">本地存储</button>
		<button @click="getStorageSync">从存储中获取</button>
		<button @click="removeStorageSync">移除存储</button>
		<button @click="login">第三方登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {

			//显示Toast
			showToast() {
				uni.showToast({
					icon: "success",
					title: "成功提示"
				})
			},
			//显示Loading
			showLoading() {
				uni.showLoading({
					title: "加载中...",
				})
				setTimeout(() => {
					uni.hideLoading()
				}, 2000)
			},
			//获取坐标
			getLocation() {
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
					}
				});
			},
			//相册选择照片
			chooseImage() {
				uni.chooseImage({
					count: 6, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePaths));
					}
				});
			},
			//本地存储
			setStorageSync() {
				uni.setStorageSync('storage_key', 'Hello World');
			},
			//从存储中获取
			getStorageSync() {
				let storage_key = uni.getStorageSync('storage_key')
				console.log(storage_key)
			},
			removeStorageSync() {
				uni.removeStorageSync('storage_key')
			},
			login() {
				uni.login({
					provider: 'weixin',
					success(res) { // 登录成功
						console.log(res); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
					},
					fail(res) { // 登录失败
						console.log(res.errCode)
						console.log(res.errMsg)
					}
				})
			}
		}
	}
</script>

<style>

</style>
